import org.hibernate.*;
import org.hibernate.cfg.*;

public class Client 
{
	public static void main(String[] args)
	{
		//step-1 creating Configuration
		Configuration conf= new Configuration();
		conf.configure("hibernate.cfg.xml");
		

		//step-1 creating SessionFactory
		SessionFactory factory = conf.buildSessionFactory();

		//step-1 creating Session
		Session session = factory.openSession();
		//step-1 creating Transaction
		/*Object o = session.get(Product.class,1);
		Product p = (Product) o;
		System.out.println(p.getProductName());
		System.out.println(p.getPrice());*/
		
		//p.setProductid(111);
		//p.setProductName("spice");
		//p.setPrice(4000);
		//Transaction tx = session.beginTransaction();
		//session.save(p);
		//session.close();
		
		Session session1 = factory.openSession();
		//Object o1 = session1.get(Product.class,111);
		//Product p1 = (Product) o1;
		//insert record
		
		Product p2 = new Product();
		p2.setProductid(3);
		p2.setProductName("nokia");
		p2.setPrice(5000);
		Transaction tx1 = session1.beginTransaction();
		//inserting record
		session1.save(p2);
		
		//p1.setPrice(9000);
		//update record
		//session1.update(p1);
		//step-1 creating Transaction
		//session1.save(p);
		//tx.commit();
		
		//deleting record
		//Object o2 = session.get(Product.class,113);
		//Product p3 = (Product) o2;
		//session1.delete(p3);
		
		tx1.commit();
		session1.close();
		System.out.println("Object saved Succssfully");
		System.out.println();
		session.close();
		factory.close();
	}//main
}//class
